package com.chagee.store.operation.server.controller;

import com.alibaba.fastjson.JSON;
import com.chagee.base.utils.HttpResponse;
import com.chagee.base.utils.HttpResponseUtil;
import com.chagee.store.operation.common.exception.BizErrorCode;
import com.chagee.store.operation.common.utils.CommonUtil;
import com.chagee.store.operation.server.facade.StoreAppEvaluateFacade;
import com.chagee.store.operation.server.model.param.EvaluateParam;
import com.chagee.store.operation.server.model.vo.EvaluateDictResponse;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author : hk
 * @Date : 2024/4/25
 */

/**
 * APP端小程序三方打烊评价
 */
@Slf4j
@RestController
@RequestMapping("/appEvaluate")
public class StoreAppEvaluateController {

	@Resource
	private StoreAppEvaluateFacade storeAppEvaluateFacade;

	@PostMapping("/evaluateDict")
	@ApiOperation("评价项列表")
	public HttpResponse<List<EvaluateDictResponse>> evaluateDict() {
		log.info("store_StoreAppEvaluateController_evaluateDict , auth:{}", JSON.toJSONString(AuthUtil.getUser()));

		List<EvaluateDictResponse> result = storeAppEvaluateFacade.evaluateDict();
		return HttpResponseUtil.success(result);
	}

	@PostMapping("/submitEvaluate")
	@ApiOperation("提交打烊评价")
	public HttpResponse<Boolean> submitEvaluate(@RequestBody @Valid EvaluateParam param) {
		log.info("store_StoreAppEvaluateController_submitEvaluate_request:{}, auth:{}", JSON.toJSONString(param), JSON.toJSONString(AuthUtil.getUser()));
		if (StringUtils.isNotBlank(CommonUtil.validate(param))) {
			return HttpResponseUtil.build(null, BizErrorCode.REQUEST_VALID_FAILED.getErrorCode(), CommonUtil.validate(param));
		}
		Boolean result = storeAppEvaluateFacade.submitEvaluate(param);
		return HttpResponseUtil.success(result);
	}
}
